<?php

namespace app\api\controller;

use app\common\controller\Api;

class Login extends Api
{

    public function index()
    {
        $data = request()->post();
        $model = model('Users');
        $info = $model->where('username', $data['username'])->find();
        if (!$info) {
            return $this->responseSend(0, '账号未注册', 160);
        }
        if (password_verify($data['password'], $info['password'])) {
            $count = db('ShopCar')
                ->where('user_id', $info['id'])
                ->count();
            $info['cartCount'] = $count;
            return $this->responseSend($info['id'], $info, 200);
        } else {
            return $this->responseSend(0, '密码错误', 160);
        }
    }
}
